import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import '../../../app_files.dart';
import '../model/normal_config_model.dart';
import 'action.dart';
import 'state.dart';
import 'dart:io';

const double kOrderImageWidth = 90;

Widget buildView(EngineerGasResultViewState state, Dispatch dispatch,
    ViewService viewService) {
  Widget _infoWidget() => Container(
        padding: EdgeInsets.only(left: 15, right: 15, bottom: 8),
        decoration: BoxDecoration(
            color: Colors.white,
            border: Border(
                bottom: BorderSide(color: ThemeConfig.separeColor, width: 10))),
        child: Column(
          children: [
            Container(
              height: 44,
              child: Align(
                alignment: Alignment.centerLeft,
                child: Text(
                  '客户信息',
                  style: TextThemeConfig.Font16WithColorBold22,
                ),
              ),
              margin: EdgeInsets.only(bottom: 4),
            ),
            Container(
              padding: EdgeInsets.symmetric(vertical: 5),
              child: Row(
                children: [
                  Text(
                    '客户姓名',
                    style: TextThemeConfig.Font14WithColor66,
                  ),
                  Padding(padding: EdgeInsets.only(left: 50)),
                  Text(
                    state.model.userName,
                    style: TextThemeConfig.Font14WithColor22,
                  ),
                ],
              ),
            ),
            Container(
              padding: EdgeInsets.symmetric(vertical: 5),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '客户地址',
                    style: TextThemeConfig.Font14WithColor66,
                  ),
                  Padding(padding: EdgeInsets.only(left: 50)),
                  Expanded(
                    child: Text(
                      state.model.address,
                      style: TextThemeConfig.Font14WithColor22,
                    ),
                  ),
                ],
              ),
            ),
            state.model.itemType == '5'
                ? Container()
                : Container(
                    padding: EdgeInsets.symmetric(vertical: 5),
                    child: Row(
                      children: [
                        Text(
                          '联系方式',
                          style: TextThemeConfig.Font14WithColor66,
                        ),
                        Padding(padding: EdgeInsets.only(left: 50)),
                        Text(
                          state.model.phone,
                          style: TextThemeConfig.Font14WithColor22,
                        ),
                      ],
                    ),
                  ),
            state.model.itemType == '6'
                ? Container(
                    padding: EdgeInsets.symmetric(vertical: 5),
                    child: Row(
                      children: [
                        Text(
                          '安装类型',
                          style: TextThemeConfig.Font14WithColor66,
                        ),
                        Padding(padding: EdgeInsets.only(left: 50)),
                        Text(
                          state.model.installTypeStr,
                          style: TextThemeConfig.Font14WithColor22,
                        ),
                      ],
                    ),
                  )
                : Container(),
            state.logList.isEmpty ? Container() : Container(
              padding: EdgeInsets.symmetric(vertical: 5),
              child: Row(
                children: [
                  Text(
                    '首次派单时间',
                    style: TextThemeConfig.Font14WithColor66,
                  ),
                  Padding(padding: EdgeInsets.only(left: 25)),
                  Text(
                    '${state.logList.first['operatetime']}',
                    style: TextThemeConfig.Font14WithColor22,
                  ),
                ],
              ),
            )
          ],
        ),
      );

  Widget _meterInfoWidget() => Container(
        padding: EdgeInsets.only(left: 15, right: 15, bottom: 8),
        decoration: BoxDecoration(
            color: Colors.white,
            border: Border(
                bottom: BorderSide(color: ThemeConfig.separeColor, width: 10))),
        child: Column(
          children: [
            Container(
              height: 44,
              child: Align(
                alignment: Alignment.centerLeft,
                child: Text(
                  '表具信息',
                  style: TextThemeConfig.Font16WithColorBold22,
                ),
              ),
              margin: EdgeInsets.only(bottom: 4),
            ),
            Container(
              padding: EdgeInsets.symmetric(vertical: 5),
              child: Row(
                children: [
                  Text(
                    '表具编号',
                    style: TextThemeConfig.Font14WithColor66,
                  ),
                  Padding(padding: EdgeInsets.only(left: 50)),
                  Text(
                    state.meterInfoModel.meterNo,
                    style: TextThemeConfig.Font14WithColor22,
                  ),
                ],
              ),
            ),
            Container(
              padding: EdgeInsets.symmetric(vertical: 5),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '表具厂家',
                    style: TextThemeConfig.Font14WithColor66,
                  ),
                  Padding(padding: EdgeInsets.only(left: 50)),
                  Expanded(
                    child: Text(
                      state.meterInfoModel.meterFactory,
                      style: TextThemeConfig.Font14WithColor22,
                    ),
                  ),
                ],
              ),
            ),
            Container(
              padding: EdgeInsets.symmetric(vertical: 5),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '表具表向',
                    style: TextThemeConfig.Font14WithColor66,
                  ),
                  Padding(padding: EdgeInsets.only(left: 50)),
                  Expanded(
                    child: Text(
                      state.meterInfoModel.meterBiaoxiang,
                      style: TextThemeConfig.Font14WithColor22,
                    ),
                  ),
                ],
              ),
            ),
            Container(
              padding: EdgeInsets.symmetric(vertical: 5),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '表具表底',
                    style: TextThemeConfig.Font14WithColor66,
                  ),
                  Padding(padding: EdgeInsets.only(left: 50)),
                  Expanded(
                    child: Text(
                      state.meterInfoModel.meterBaseVolume,
                      style: TextThemeConfig.Font14WithColor22,
                    ),
                  ),
                ],
              ),
            ),
            Container(
              padding: EdgeInsets.symmetric(vertical: 5),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '是否加封',
                    style: TextThemeConfig.Font14WithColor66,
                  ),
                  Padding(padding: EdgeInsets.only(left: 50)),
                  Expanded(
                    child: Text(
                      state.meterInfoModel.isClosed == 0 ? '未加封' : '已加封',
                      style: TextThemeConfig.Font14WithColor22,
                    ),
                  ),
                ],
              ),
            ),
            state.meterInfoModel.isClosed == 0
                ? Container()
                : Container(
                    padding: EdgeInsets.symmetric(vertical: 5),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          '表具封号',
                          style: TextThemeConfig.Font14WithColor66,
                        ),
                        Padding(padding: EdgeInsets.only(left: 50)),
                        Expanded(
                          child: Text(
                            state.meterInfoModel.meterFengNumber,
                            style: TextThemeConfig.Font14WithColor22,
                          ),
                        ),
                      ],
                    ),
                  ),
          ],
        ),
      );
  double total = 0.0;
  for (var item in state.materList) {
    total += (item.price * item.number);
  }
  Widget _materListWidget() => Container(
        padding: EdgeInsets.only(left: 15, right: 15, bottom: 8),
        decoration: BoxDecoration(
            color: Colors.white,
            border: Border(
                bottom: BorderSide(color: ThemeConfig.separeColor, width: 10))),
        child: Column(
          children: [
            Container(
              height: 44,
              child: Align(
                alignment: Alignment.centerLeft,
                child: Text(
                  '材料清单',
                  style: TextThemeConfig.Font16WithColorBold22,
                ),
              ),
              margin: EdgeInsets.only(bottom: 4),
            ),
            Container(
              color: ThemeConfig.lineColor,
              height: 33,
              child: Row(
                children: [
                  Padding(padding: EdgeInsets.only(left: 8)),
                  Expanded(
                    child: Text(
                      '材料',
                      style: TextThemeConfig.Font14WithColor22,
                    ),
                  ),
                  Container(
                    width: 30,
                    child: Text(
                      '数量',
                      style: TextThemeConfig.Font14WithColor22,
                    ),
                  ),
                  Container(
                      width: 50,
                      child: Align(
                        alignment: Alignment.centerRight,
                        child: Text(
                          '单价',
                          style: TextThemeConfig.Font14WithColor22,
                        ),
                      )),
                  Container(
                      width: 60,
                      child: Align(
                        alignment: Alignment.centerRight,
                        child: Text(
                          '价格',
                          style: TextThemeConfig.Font14WithColor22,
                        ),
                      )),
                  Padding(padding: EdgeInsets.only(left: 8)),
                ],
              ),
            ),
            Container(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: state.materList
                    .map((e) => e.number == 0 ? Container() : Container(
                          height: 33,
                          padding: EdgeInsets.only(left: 8, right: 8),
                          child: Row(
                            children: [
                              Expanded(
                                child: Text(
                                  e.materName,
                                  style: TextThemeConfig.Font14WithColor22,
                                ),
                              ),
                              Container(
                                width: 30,
                                child: Text(
                                  '${e.number}',
                                  style: TextThemeConfig.Font14WithColor22,
                                ),
                              ),
                              Container(
                                  width: 50,
                                  child: Align(
                                    alignment: Alignment.centerRight,
                                    child: Text(
                                      '${e.price}',
                                      style: TextThemeConfig.Font14WithColor22,
                                    ),
                                  )),
                              Container(
                                  width: 60,
                                  child: Align(
                                    alignment: Alignment.centerRight,
                                    child: Text(
                                      '${e.price * e.number}',
                                      style: TextThemeConfig.Font14WithColor22,
                                    ),
                                  )),
                            ],
                          ),
                        ))
                    .toList(),
              ),
            ),
            Container(
              child: Row(
                children: [
                  Expanded(child: Container()),
                  Text(
                    '价格总计 : ',
                    style: TextThemeConfig.Font14WithColor22,
                  ),
                  Text(
                    '$total',
                    style: TextThemeConfig.Font14WithColorRed,
                  ),
                  Padding(padding: EdgeInsets.only(right: 8))
                ],
              ),
            ),
          ],
        ),
      );

  Widget _orderResultWidget() {
    return NormalConfigResultWidget(
        state.items,
        (type, model, {dynamic file}) => dispatch(
            EngineerGasResultViewActionCreator.onTapResultPic(model, file)));
  }

  Widget _orderStatusWidget() {
    List<String> titles = ['已解决', '未解决'];
    Widget _button(int index, String text) {
      int t = state.isSolve == null
          ? -1
          : state.isSolve
              ? 0
              : 1;
      return InkWell(
        child: Container(
          width: 80,
          height: 30,
          margin: EdgeInsets.only(right: 20, bottom: 20),
          decoration: BoxDecoration(
            color: t == index ? Color(0xffE6EEFF) : Color(0xfff5f5f5),
            borderRadius: BorderRadius.all(Radius.circular(4)),
          ),
          child: Align(
            child: Text(
              text,
              style: t == index
                  ? TextThemeConfig.Font13WithColorblue
                  : TextThemeConfig.Font13WithColor66,
            ),
          ),
        ),
        onTap: () {
          if (!state.isDetail) {
            dispatch(
                EngineerGasResultViewActionCreator.onTapStatus(index == 0));
          }
        },
      );
    }

    List<Widget> items = [];
    for (int i = 0; i < 2; ++i) {
      items.add(_button(i, titles[i]));
    }

    return Container(
      padding: EdgeInsets.only(left: 15, right: 15),
      decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
              bottom: BorderSide(color: ThemeConfig.separeColor, width: 10))),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            height: 44,
            child: Align(
              alignment: Alignment.centerLeft,
              child: Text(
                '报装结果',
                style: TextThemeConfig.Font16WithColorBold22,
              ),
            ),
            margin: EdgeInsets.only(bottom: 4),
          ),
          Container(
            child: Row(
              children: state.isDetail
                  ? [
                      Padding(
                        padding: EdgeInsets.only(bottom: 12),
                        child: Text(
                          state.isSolve ? '已解决' : '未解决',
                          style: TextThemeConfig.Font13WithColor22,
                        ),
                      )
                    ]
                  : items,
            ),
          ),
        ],
      ),
    );
  }

  Widget _orderPhotoWidget() {
    if (state.orderPhoto.isEmpty && state.isDetail) return Container();
    return Container(
      padding: EdgeInsets.only(left: 15, right: 15),
      decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
              bottom: BorderSide(color: ThemeConfig.separeColor, width: 10))),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            height: 44,
            child: Align(
              alignment: Alignment.centerLeft,
              child: Text(
                '拍照留存',
                style: TextThemeConfig.Font16WithColorBold22,
              ),
            ),
            margin: EdgeInsets.only(bottom: 4),
          ),
          Container(
            margin: EdgeInsets.only(bottom: 12),
            height: kOrderImageWidth,
            child: ListView.builder(
              itemBuilder: (BuildContext context, int index) {
                if (index == state.orderPhoto.length) {
                  return InkWell(
                    child: Container(
                      margin: EdgeInsets.only(right: 12),
                      width: kOrderImageWidth,
                      height: kOrderImageWidth,
                      color: Color(0xffF5F5F5),
                      child: Align(
                        child: Image.asset('images/icon_camera.png'),
                      ),
                    ),
                    onTap: () => dispatch(
                        EngineerGasResultViewActionCreator.onTapAddPic()),
                  );
                } else {
                  var file = state.orderPhoto[index];
                  return InkWell(
                    child: Container(
                      margin: EdgeInsets.only(right: 12),
                      child: file is File
                          ? Image(
                              image: FileImageEx(file),
                              width: kOrderImageWidth,
                              height: kOrderImageWidth,
                              fit: BoxFit.fill,
                            )
                          : CustomImage(
                              file,
                              fit: BoxFit.fill,
                              width: kOrderImageWidth,
                              height: kOrderImageWidth,
                            ),
                    ),
                    onTap: () => dispatch(
                        EngineerGasResultViewActionCreator.onTapPic(file)),
                  );
                }
              },
              itemCount: state.isDetail
                  ? state.orderPhoto.length
                  : state.orderPhoto.length + 1,
              scrollDirection: Axis.horizontal,
              itemExtent: kOrderImageWidth + 12,
              padding: EdgeInsets.only(),
            ),
          )
        ],
      ),
    );
  }

  Widget _newversionWidget() {
    String imgInfo =
    CommonUtils.checkNullToString(state.model.businessExtend['imgInfo']);
    List images = [];
    if (imgInfo.isNotEmpty) {
      images = imgInfo.split(',');
    }

    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        ///隐患待排查
        CommonUtils.checkNullToString(state.model.businessExtend['remark']).isEmpty ? Container() :  Container(
          padding: EdgeInsets.only(left: 15, right: 15),
          decoration: BoxDecoration(
              color: Colors.white,
              border: Border(
                  bottom:
                  BorderSide(color: ThemeConfig.separeColor, width: 10))),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                height: 44,
                child: Align(
                  alignment: Alignment.centerLeft,
                  child: Text(
                    '隐患待排查',
                    style: TextThemeConfig.Font16WithColorBold22,
                  ),
                ),
                margin: EdgeInsets.only(bottom: 4),
              ),
              CommonUtils.checkNullToString(
                  state.model.businessExtend['dangerTime']).isEmpty ? Container() :  Container(
                padding: EdgeInsets.only(bottom: 12),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      '上报时间：',
                      style: TextThemeConfig.Font14WithColor22,
                    ),
                    Padding(padding: EdgeInsets.only(left: 50)),
                    Expanded(
                      child: Text(
                        CommonUtils.checkNullToString(
                            state.model.businessExtend['dangerTime']),
                        style: TextThemeConfig.Font14WithColor22,
                      ),
                    ),
                  ],
                ),
              ),
              Container(
                height: 100,
                child: Text(
                  CommonUtils.checkNullToString(
                      state.model.businessExtend['remark']),
                  style: TextThemeConfig.Font13WithColor22,
                ),
              ),
              images.isEmpty
                  ? Container()
                  : Container(
                decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border(
                        bottom: BorderSide(
                            color: ThemeConfig.separeColor, width: 10))),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [

                    Container(
                      margin: EdgeInsets.only(bottom: 12),
                      height: 90,
                      child: ListView.builder(
                        itemBuilder: (BuildContext context, int index) {
                          var file = images[index];
                          return InkWell(
                            child: Container(
                              margin: EdgeInsets.only(right: 12),
                              child: file is File
                                  ? Image(
                                image: FileImageEx(file),
                                width: 90,
                                height: 90,
                                fit: BoxFit.fill,
                              )
                                  : CustomImage(
                                file,
                                fit: BoxFit.fill,
                                width: 90,
                                height: 90,
                              ),
                            ),
                            onTap: () {
                              CommonUtils.showMediaAlbumView(
                                viewService.context,
                                initialIndex: state.orderPhoto.indexOf(file),
                                files: images,
                              );
                            },
                          );
                        },
                        itemCount: images.length,
                        scrollDirection: Axis.horizontal,
                        itemExtent: 112,
                        padding: EdgeInsets.only(),
                      ),
                    )
                  ],
                ),
              )
            ],
          ),
        ),
        ///身份证号
        state.idCard.isEmpty && state.isDetail
            ? Container() : Container(
          padding: EdgeInsets.only(left: 15, right: 15),
          decoration: BoxDecoration(
              color: Colors.white,
              border: Border(
                  bottom:
                      BorderSide(color: ThemeConfig.separeColor, width: 10))),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                height: 44,
                child: Align(
                  alignment: Alignment.centerLeft,
                  child: Text(
                    '身份证号',
                    style: TextThemeConfig.Font16WithColorBold22,
                  ),
                ),
                margin: EdgeInsets.only(bottom: 4),
              ),
              Container(
                margin: EdgeInsets.only(bottom: 12),
                height: 24,
                child: TextField(
                  style: TextThemeConfig.Font14WithColor22,
                  controller: TextEditingController(text: state.idCard),
                  decoration: InputDecoration(
                    border: InputBorder.none,
                    hintText: "请输入身份证号",
                    hintStyle: TextThemeConfig.Font14WithColor99,
                    contentPadding: EdgeInsets.only(bottom: 12),
                  ),
                  onChanged: (text) => state.idCard = text,
                  enabled: !state.isDetail,
                ),
              )
            ],
          ),
        ),

        ///身份证照片
        state.isDetail &&state.idCardFrontImg.isEmpty && state.idCardBackImg.isEmpty
            ? Container() :
        Container(
          padding: EdgeInsets.only(left: 15, right: 15),
          decoration: BoxDecoration(
              color: Colors.white,
              border: Border(
                  bottom:
                      BorderSide(color: ThemeConfig.separeColor, width: 10))),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                height: 44,
                child: Align(
                  alignment: Alignment.centerLeft,
                  child: Text(
                    '身份证照片',
                    style: TextThemeConfig.Font16WithColorBold22,
                  ),
                ),
                margin: EdgeInsets.only(bottom: 4),
              ),
              Row(
                children: [
                  Container(
                    margin: EdgeInsets.only(bottom: 12),
                    width: 150,
                    height: 94,
                    child: InkWell(
                      child: Container(
                        margin: EdgeInsets.only(right: 12),
                        child: state.idCardFrontImg == null
                            ? Image.asset('images/img_zheng.png')
                            : state.idCardFrontImg is File
                            ? Image(image: FileImageEx(state.idCardFrontImg))
                            : CustomImage(
                          state.idCardFrontImg,
                          width: 150,
                          height: 94,
                        ),
                      ),
                      onTap: () =>
                          dispatch(EngineerGasResultViewActionCreator.onTapIdCard('zheng')),
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(bottom: 12),
                    width: 150,
                    height: 94,
                    child: InkWell(
                      child: Container(
                        margin: EdgeInsets.only(right: 12),
                        child: state.idCardBackImg == null
                            ? Image.asset('images/img_fan.png')
                            : state.idCardBackImg is File
                            ? Image(image: FileImageEx(state.idCardBackImg))
                            : CustomImage(
                          state.idCardBackImg,
                          width: 150,
                          height: 94,
                        ),
                      ),
                      onTap: () =>
                          dispatch(EngineerGasResultViewActionCreator.onTapIdCard('fan')),
                    ),
                  ),
                ],
              )
            ],
          ),
        ),

        /// 管道照片
        state.pipelineImg.isEmpty && state.isDetail
            ? Container()
            : Container(
                padding: EdgeInsets.only(left: 15, right: 15),
                decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border(
                        bottom: BorderSide(
                            color: ThemeConfig.separeColor, width: 10))),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      height: 44,
                      child: Align(
                        alignment: Alignment.centerLeft,
                        child: Text(
                          '管道照片',
                          style: TextThemeConfig.Font16WithColorBold22,
                        ),
                      ),
                      margin: EdgeInsets.only(bottom: 4),
                    ),
                    Container(
                      margin: EdgeInsets.only(bottom: 12),
                      height: kOrderImageWidth,
                      child: ListView.builder(
                        itemBuilder: (BuildContext context, int index) {
                          if (index == state.pipelineImg.length) {
                            return InkWell(
                              child: Container(
                                margin: EdgeInsets.only(right: 12),
                                width: kOrderImageWidth,
                                height: kOrderImageWidth,
                                color: Color(0xffF5F5F5),
                                child: Align(
                                  child: Image.asset('images/icon_camera.png'),
                                ),
                              ),
                              onTap: () => dispatch(
                                  EngineerGasResultViewActionCreator
                                      .onTapAddGasPic('pipelineImg')),
                            );
                          } else {
                            var file = state.pipelineImg[index];
                            return InkWell(
                              child: Container(
                                margin: EdgeInsets.only(right: 12),
                                child: file is File
                                    ? Image(
                                        image: FileImageEx(file),
                                        width: kOrderImageWidth,
                                        height: kOrderImageWidth,
                                        fit: BoxFit.fill,
                                      )
                                    : CustomImage(
                                        file,
                                        fit: BoxFit.fill,
                                        width: kOrderImageWidth,
                                        height: kOrderImageWidth,
                                      ),
                              ),
                              onTap: () => dispatch(
                                  EngineerGasResultViewActionCreator
                                      .onTapGasPic('pipelineImg', file)),
                            );
                          }
                        },
                        itemCount: state.isDetail
                            ? state.pipelineImg.length
                            : state.pipelineImg.length + 1,
                        scrollDirection: Axis.horizontal,
                        itemExtent: kOrderImageWidth + 12,
                        padding: EdgeInsets.only(),
                      ),
                    )
                  ],
                ),
              ),

        /// 燃气表照片
        state.gasMeterImg.isEmpty && state.isDetail
            ? Container()
            : Container(
                padding: EdgeInsets.only(left: 15, right: 15),
                decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border(
                        bottom: BorderSide(
                            color: ThemeConfig.separeColor, width: 10))),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      height: 44,
                      child: Align(
                        alignment: Alignment.centerLeft,
                        child: Text(
                          '燃气表照片',
                          style: TextThemeConfig.Font16WithColorBold22,
                        ),
                      ),
                      margin: EdgeInsets.only(bottom: 4),
                    ),
                    Container(
                      margin: EdgeInsets.only(bottom: 12),
                      height: kOrderImageWidth,
                      child: ListView.builder(
                        itemBuilder: (BuildContext context, int index) {
                          if (index == state.gasMeterImg.length) {
                            return InkWell(
                              child: Container(
                                margin: EdgeInsets.only(right: 12),
                                width: kOrderImageWidth,
                                height: kOrderImageWidth,
                                color: Color(0xffF5F5F5),
                                child: Align(
                                  child: Image.asset('images/icon_camera.png'),
                                ),
                              ),
                              onTap: () => dispatch(
                                  EngineerGasResultViewActionCreator
                                      .onTapAddGasPic('gasMeterImg')),
                            );
                          } else {
                            var file = state.gasMeterImg[index];
                            return InkWell(
                              child: Container(
                                margin: EdgeInsets.only(right: 12),
                                child: file is File
                                    ? Image(
                                        image: FileImageEx(file),
                                        width: kOrderImageWidth,
                                        height: kOrderImageWidth,
                                        fit: BoxFit.fill,
                                      )
                                    : CustomImage(
                                        file,
                                        fit: BoxFit.fill,
                                        width: kOrderImageWidth,
                                        height: kOrderImageWidth,
                                      ),
                              ),
                              onTap: () => dispatch(
                                  EngineerGasResultViewActionCreator
                                      .onTapGasPic('gasMeterImg', file)),
                            );
                          }
                        },
                        itemCount: state.isDetail
                            ? state.gasMeterImg.length
                            : state.gasMeterImg.length + 1,
                        scrollDirection: Axis.horizontal,
                        itemExtent: kOrderImageWidth + 12,
                        padding: EdgeInsets.only(),
                      ),
                    )
                  ],
                ),
              ),

        /// 全景图
        state.panoramagramImg.isEmpty && state.isDetail
            ? Container()
            : Container(
                padding: EdgeInsets.only(left: 15, right: 15),
                decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border(
                        bottom: BorderSide(
                            color: ThemeConfig.separeColor, width: 10))),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      height: 44,
                      child: Align(
                        alignment: Alignment.centerLeft,
                        child: Text(
                          '全景图',
                          style: TextThemeConfig.Font16WithColorBold22,
                        ),
                      ),
                      margin: EdgeInsets.only(bottom: 4),
                    ),
                    Container(
                      margin: EdgeInsets.only(bottom: 12),
                      height: kOrderImageWidth,
                      child: ListView.builder(
                        itemBuilder: (BuildContext context, int index) {
                          if (index == state.panoramagramImg.length) {
                            return InkWell(
                              child: Container(
                                margin: EdgeInsets.only(right: 12),
                                width: kOrderImageWidth,
                                height: kOrderImageWidth,
                                color: Color(0xffF5F5F5),
                                child: Align(
                                  child: Image.asset('images/icon_camera.png'),
                                ),
                              ),
                              onTap: () => dispatch(
                                  EngineerGasResultViewActionCreator
                                      .onTapAddGasPic('panoramagramImg')),
                            );
                          } else {
                            var file = state.panoramagramImg[index];
                            return InkWell(
                              child: Container(
                                margin: EdgeInsets.only(right: 12),
                                child: file is File
                                    ? Image(
                                        image: FileImageEx(file),
                                        width: kOrderImageWidth,
                                        height: kOrderImageWidth,
                                        fit: BoxFit.fill,
                                      )
                                    : CustomImage(
                                        file,
                                        fit: BoxFit.fill,
                                        width: kOrderImageWidth,
                                        height: kOrderImageWidth,
                                      ),
                              ),
                              onTap: () => dispatch(
                                  EngineerGasResultViewActionCreator
                                      .onTapGasPic('panoramagramImg', file)),
                            );
                          }
                        },
                        itemCount: state.isDetail
                            ? state.panoramagramImg.length
                            : state.panoramagramImg.length + 1,
                        scrollDirection: Axis.horizontal,
                        itemExtent: kOrderImageWidth + 12,
                        padding: EdgeInsets.only(),
                      ),
                    )
                  ],
                ),
              ),

        /// 营业执照照片
        state.businessLicenseImg.isEmpty && state.isDetail
            ? Container()
            : Container(
                padding: EdgeInsets.only(left: 15, right: 15),
                decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border(
                        bottom: BorderSide(
                            color: ThemeConfig.separeColor, width: 10))),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      height: 44,
                      child: Align(
                        alignment: Alignment.centerLeft,
                        child: Text(
                          '营业执照照片',
                          style: TextThemeConfig.Font16WithColorBold22,
                        ),
                      ),
                      margin: EdgeInsets.only(bottom: 4),
                    ),
                    Container(
                      margin: EdgeInsets.only(bottom: 12),
                      height: kOrderImageWidth,
                      child: ListView.builder(
                        itemBuilder: (BuildContext context, int index) {
                          if (index == state.businessLicenseImg.length) {
                            return InkWell(
                              child: Container(
                                margin: EdgeInsets.only(right: 12),
                                width: kOrderImageWidth,
                                height: kOrderImageWidth,
                                color: Color(0xffF5F5F5),
                                child: Align(
                                  child: Image.asset('images/icon_camera.png'),
                                ),
                              ),
                              onTap: () => dispatch(
                                  EngineerGasResultViewActionCreator
                                      .onTapAddGasPic('businessLicenseImg')),
                            );
                          } else {
                            var file = state.businessLicenseImg[index];
                            return InkWell(
                              child: Container(
                                margin: EdgeInsets.only(right: 12),
                                child: file is File
                                    ? Image(
                                        image: FileImageEx(file),
                                        width: kOrderImageWidth,
                                        height: kOrderImageWidth,
                                        fit: BoxFit.fill,
                                      )
                                    : CustomImage(
                                        file,
                                        fit: BoxFit.fill,
                                        width: kOrderImageWidth,
                                        height: kOrderImageWidth,
                                      ),
                              ),
                              onTap: () => dispatch(
                                  EngineerGasResultViewActionCreator
                                      .onTapGasPic('businessLicenseImg', file)),
                            );
                          }
                        },
                        itemCount: state.isDetail
                            ? state.businessLicenseImg.length
                            : state.businessLicenseImg.length + 1,
                        scrollDirection: Axis.horizontal,
                        itemExtent: kOrderImageWidth + 12,
                        padding: EdgeInsets.only(),
                      ),
                    )
                  ],
                ),
              ),

        /// 视频
        state.videoUrl.isEmpty && state.isDetail
            ? Container()
            : Container(
                padding: EdgeInsets.only(left: 15, right: 15),
                decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border(
                        bottom: BorderSide(
                            color: ThemeConfig.separeColor, width: 10))),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      height: 44,
                      child: Align(
                        alignment: Alignment.centerLeft,
                        child: Text(
                          '视频',
                          style: TextThemeConfig.Font16WithColorBold22,
                        ),
                      ),
                      margin: EdgeInsets.only(bottom: 4),
                    ),
                    Container(
                      margin: EdgeInsets.only(bottom: 12),
                      height: kOrderImageWidth,
                      child: ListView.builder(
                        itemBuilder: (BuildContext context, int index) {
                          if (index == state.videoUrl.length) {
                            return InkWell(
                              child: Container(
                                margin: EdgeInsets.only(right: 12),
                                width: kOrderImageWidth,
                                height: kOrderImageWidth,
                                color: Color(0xffF5F5F5),
                                child: Align(
                                  child: Image.asset('images/icon_camera.png'),
                                ),
                              ),
                              onTap: () => dispatch(
                                  EngineerGasResultViewActionCreator
                                      .onTapAddGasPic('videoUrl')),
                            );
                          } else {
                            var file = state.videoUrl[index];
                            return InkWell(
                              child: Container(
                                margin: EdgeInsets.only(right: 12),
                                child: file is File
                                    ? Image(
                                        image: FileImageEx(file),
                                        width: kOrderImageWidth,
                                        height: kOrderImageWidth,
                                        fit: BoxFit.fill,
                                      )
                                    : CustomImage(
                                        file,
                                        fit: BoxFit.fill,
                                        width: kOrderImageWidth,
                                        height: kOrderImageWidth,
                                      ),
                              ),
                              onTap: () => dispatch(
                                  EngineerGasResultViewActionCreator
                                      .onTapGasPic('videoUrl', file)),
                            );
                          }
                        },
                        itemCount: state.isDetail
                            ? state.videoUrl.length
                            : state.videoUrl.length + 1,
                        scrollDirection: Axis.horizontal,
                        itemExtent: kOrderImageWidth + 12,
                        padding: EdgeInsets.only(),
                      ),
                    )
                  ],
                ),
              ),
      ],
    );
  }

  Widget _confirmButton() {
    if (state.isDetail) return Container();
    return Column(
      children: [
        // Container(
        //   margin: EdgeInsets.only(left: 15, right: 15),
        //   height: 45,
        //   child: InkWell(
        //     child: Center(
        //       child: Text(
        //         '临时上传',
        //         style: TextThemeConfig.Font14WithMainColor,
        //       ),
        //     ),
        //     onTap: () =>
        //         dispatch(EngineerGasResultViewActionCreator.onSave()),
        //   ),
        // ),
        Container(
          margin: EdgeInsets.only(left: 15, right: 15, top: 12, bottom: 40),
          height: 50,
          decoration: BoxDecoration(
            color: ThemeConfig.mainColor,
            borderRadius: BorderRadius.all(Radius.circular(4)),
          ),
          child: InkWell(
            child: Align(
              child: Text(
                state.orderSignPhoto == null ? '确认无误去签名' : '提交工单',
                style: TextThemeConfig.Font16WithWhite,
              ),
            ),
            onTap: () =>
                dispatch(EngineerGasResultViewActionCreator.onSubmit(false)),
          ),
        )
      ],
    );
  }

  Widget _signPhotoWidget() {
    if (state.orderSignPhoto == null || state.orderSignPhoto.toString().isEmpty)
      return Container();
    return Container(
      padding: EdgeInsets.only(left: 15, right: 15),
      decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
              bottom: BorderSide(color: ThemeConfig.separeColor, width: 10))),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            height: 44,
            child: Align(
              alignment: Alignment.centerLeft,
              child: Text(
                '电子签名',
                style: TextThemeConfig.Font16WithColorBold22,
              ),
            ),
            margin: EdgeInsets.only(bottom: 4),
          ),
          Container(
            margin: EdgeInsets.only(bottom: 12),
            height: 100,
            width: 175,
            child: InkWell(
              child: Container(
                margin: EdgeInsets.only(right: 12),
                child: state.orderSignPhoto is File
                    ? Image(image: FileImageEx(state.orderSignPhoto))
                    : CustomImage(
                        state.orderSignPhoto,
                        width: 175,
                        height: 100,
                      ),
              ),
              onTap: () =>
                  dispatch(EngineerGasResultViewActionCreator.onTapSign()),
            ),
          )
        ],
      ),
    );
  }

  return Scaffold(
    appBar: myAppBar(
      viewService.context,
      title: state.isDetail ? '工单详情' : '客户确认',
    ),
    body: SafeArea(
      child: SingleChildScrollView(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            _infoWidget(),
            state.meterInfoModel == null ? Container() : _meterInfoWidget(),
            state.materList.isEmpty ? Container() : _materListWidget(),
            state.items == null
                ? Container(
                    height: 500,
                    child: Center(
                      child: MyLoadingWidget(),
                    ),
                  )
                : MyInkWellWidget(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        // _gasWidget(),
                        _orderResultWidget(),
                        _orderStatusWidget(),
                        state.model.itemType != '6'
                            ? _orderPhotoWidget()
                            : _newversionWidget(),
                        _signPhotoWidget(),
                        _confirmButton(),
                      ],
                    ),
                    onTap: () => CommonUtils.closeKey(viewService.context),
                  )
          ],
        ),
      ),
    ),
  );
}

class NormalConfigResultWidget extends StatelessWidget {
  final List<NormalConfigModel> items;

  // final Dispatch dispatch;
  final void Function(
    String type,
    NormalConfigModel model, {
    dynamic file,
  }) onTap;

  const NormalConfigResultWidget(this.items, this.onTap);

  @override
  Widget build(BuildContext context) {
    Widget _buildItem(NormalConfigModel model) {
      return Container(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              width: double.infinity,
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    width: 150,
                    child: Text(
                      model.configName,
                      style: TextThemeConfig.Font14WithColor66,
                    ),
                  ),
                  Expanded(
                    child: Text(
                      model.valueStr,
                      style: TextThemeConfig.Font14WithColor22,
                    ),
                  ),
                ],
              ),
            ),
            (model.imageList == null || model.imageList.length == 0)
                ? Container()
                : Container(
                    margin: EdgeInsets.only(top: 8, bottom: 3),
                    height: 90,
                    child: ListView.builder(
                      itemBuilder: (BuildContext context, int index) {
                        var file = model.imageList[index];
                        return InkWell(
                          child: Container(
                            margin: EdgeInsets.only(right: 12),
                            child: file is File
                                ? Image(
                                    image: FileImageEx(file),
                                    width: 90,
                                    height: 90,
                                    fit: BoxFit.fill,
                                  )
                                : CustomImage(
                                    file,
                                    fit: BoxFit.fill,
                                    width: 90,
                                    height: 90,
                                  ),
                          ),
                          onTap: () =>
                              onTap('onTapResultPic', model, file: file),
                        );
                      },
                      itemCount: model.imageList.length,
                      scrollDirection: Axis.horizontal,
                      itemExtent: 102,
                      padding: EdgeInsets.only(),
                    ),
                  ),
          ],
        ),
        padding: EdgeInsets.only(bottom: 10),
      );
    }

    List<Widget> _children = items.map((e) => _buildItem(e)).toList();

    return Container(
      padding: EdgeInsets.only(left: 15, right: 15, bottom: 8),
      decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
              bottom: BorderSide(color: ThemeConfig.separeColor, width: 10))),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            height: 44,
            child: Align(
              alignment: Alignment.centerLeft,
              child: Text(
                '工单详情',
                style: TextThemeConfig.Font16WithColorBold22,
              ),
            ),
            margin: EdgeInsets.only(bottom: 4),
          ),
          Column(
            children: _children,
          )
        ],
      ),
    );
  }
}
